package com.woniu.after.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniu.after.client.RefundsApplyManageClient;
import com.woniu.after.client.param.CrowdRefundsMoneyParam;
import com.woniu.after.client.param.RefundsApplyParam;
import com.woniu.after.client.param.RefundsMoneyParam;
import com.woniu.after.client.result.RefundsApplyResultInfo;
import com.woniu.after.client.result.RefundsResultInfo;
import com.woniu.after.service.RefundresonService;
import com.woniu.after.service.RefundsApplyService;
import com.woniu.after.service.RefundsService;
import com.woniu.after.service.dto.RefundsApplyDto;
import com.woniu.after.service.dto.RefundsDto;
import com.woniu.after.service.form.CrowdRefundsMoneyForm;
import com.woniu.after.service.form.RefundsApplyForm;
import com.woniu.after.service.form.RefundsMoneyForm;
import com.woniu.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
public class RefundsApplyManageApiImpl implements RefundsApplyManageClient {

    @Resource
    private RefundsApplyService refundsApplyService;

    @Resource
    private RefundsService RefundsService;

    @Override
    public Result refundsApply(RefundsApplyParam refundsApplyParam) {
        log.info("退款申请:{}", refundsApplyParam);
        RefundsApplyForm refundsApplyForm = BeanUtil.copyProperties(refundsApplyParam, RefundsApplyForm.class);
        System.out.println(refundsApplyForm);
        RefundsApplyDto refundsApplyDto = refundsApplyService.refundsApply(refundsApplyForm);
        RefundsApplyResultInfo refundsApplyResultInfo = BeanUtil.copyProperties(refundsApplyDto, RefundsApplyResultInfo.class);
        return Result.getInstance(RefundsApplyResultInfo.class).setMsg("申请成功").setCode(200).setData(refundsApplyResultInfo);
    }

    @Override
    public Result refundsMoney(RefundsMoneyParam refundsMoneyParam) {
        log.info("退款申请处理:{}", refundsMoneyParam);
        RefundsMoneyForm refundsMoneyForm = BeanUtil.copyProperties(refundsMoneyParam, RefundsMoneyForm.class);
        RefundsDto refundsDto = refundsApplyService.refundsMoney(refundsMoneyForm);
        RefundsResultInfo refundsResultInfo = BeanUtil.copyProperties(refundsDto, RefundsResultInfo.class);
        return Result.getInstance(RefundsResultInfo.class).setMsg("处理成功").setCode(200).setData(refundsResultInfo);
    }

    @Override
    public Result crowdRefundsMoney(CrowdRefundsMoneyParam crowdRefundsMoneyParam) {
        log.info("众筹退款:{}", crowdRefundsMoneyParam);
        CrowdRefundsMoneyForm crowdRefundsMoneyForm = BeanUtil.copyProperties(crowdRefundsMoneyParam, CrowdRefundsMoneyForm.class);
        RefundsDto refundsDto = RefundsService.crowdRefundsMoney(crowdRefundsMoneyForm);
        RefundsResultInfo refundsResultInfo = BeanUtil.copyProperties(refundsDto, RefundsResultInfo.class);
        return Result.getInstance(RefundsResultInfo.class).setMsg("退款成功").setCode(200).setData(refundsResultInfo);
    }
}
